/**
 * 
 */
package qy.jalgotrade.broker.backtesting;

import qy.jalgotrade.broker.Order;

/**
 * A :class:`Commission` class that charges a fixed amount for the whole trade.
 * 
 * @author qy
 *
 */
public class FixedPerTrade extends Commission {

	/**
	 * The commission for an order.
	 */
	private double __amount;

	/**
	 * 
	 * @param amount
	 *            The commission for an order.
	 */
	public FixedPerTrade(double amount) {

		__amount = amount;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see qy.jalgotrade.broker.backtesting.Commission#calculate(qy.jalgotrade.broker.Order,
	 * double, double)
	 */
	@Override
	public double calculate(Order order, double price, double quantity) {

		double ret = 0.0;
		// Only charge the first fill.
		if (order.getExecutionInfo() == null) {
			ret = __amount;
		}

		return ret;
	}
}
